package com.atguigu.juc.homework3;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;
import java.util.concurrent.TimeUnit;

class MyCallable implements Callable<Integer> {

    @Override
    public Integer call() throws Exception {
        System.out.println(Thread.currentThread().getName()+"永远的hello world！！！");
        return 1024;
    }
}

public class TestCallable {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        MyCallable myCallable=new MyCallable();
        FutureTask<Integer> futureTask1=new FutureTask<Integer>(()->{
            System.out.println(Thread.currentThread().getName()+"futureTask");
            TimeUnit.SECONDS.sleep(3);
            return 2048;
        });

        FutureTask<Integer> futureTask2=new FutureTask<Integer>(()->{
            System.out.println(Thread.currentThread().getName()+"futureTask");
            TimeUnit.SECONDS.sleep(3);
            return 4096;
        });

            new Thread(futureTask1,"线程名称1").start();
            new Thread(futureTask2,"线程名称2").start();
        System.out.println("futureTask.get() = " + futureTask1.get());
        System.out.println("futureTask.get() = " + futureTask2.get());
        System.out.println("yyds");
    }
}
